<template>
  <div class="card-container">
    <div class="card-img">
      <img :src="img">
    </div>
    <div class="content">
      <div class="left-info">
        <div class="card-time">
          <CalendarOutlined />
          <span>发布于 {{ time }}</span>
        </div>
        <div class="card-title">{{ title }}</div>
        <div class="card-interact">
          <span>
            <svg class="icon" aria-hidden="true" width="16" height="16">
              <use xlink:href="#icon-liulan"></use>
            </svg>
            <span>&nbsp;{{ cardData.viewCount }} 浏览</span>
          </span>&nbsp;&nbsp;
          <span>
            <svg class="icon" aria-hidden="true" width="16" height="16">
              <use xlink:href="#icon-pinglun"></use>
            </svg>
            <span>&nbsp;{{ cardData.commentCount }} 评论</span>
          </span>
        </div>
      </div>
      <div class="card-tag">
        <div class="tag-item" v-for="(item, index) in tagList" :key="item.id">
          <svg v-if="index % 2 == 0" class="icon" aria-hidden="true" width="16" height="16">
            <use xlink:href="#icon-biaoqian1"></use>
          </svg>
          <svg v-if="index % 2 == 1" class="icon" aria-hidden="true" width="16" height="16">
            <use xlink:href="#icon-biaoqian"></use>
          </svg>
          &nbsp;
          <span>{{ item.tagName }}</span>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, reactive, computed, watch } from 'vue';
import { CalendarOutlined } from '@ant-design/icons-vue';

const props = defineProps({
  cardData: {
    type: Object,
    default: {},
  },
  idx: {
    type: Number,
    default: 0,
  },
});
watch(() => props.cardData, () => {
  console.log('cardData', cardData);
})
const { cardData, idx } = props;

const flexDirection = computed(() => {
  return idx % 2 === 0 ? 'row-reverse' : 'row';
});

const img = ref(cardData.thumbnail);
const time = ref(cardData.createTime);
const title = ref(cardData.title);
const tagList = ref(cardData.articleTagList)

</script>

<style scoped lang="less">
.card-container {
  width: 100%;
  height: 300px;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
  transition: all 0.1s linear;
  cursor: pointer;
  display: flex;
  flex-direction: v-bind(flexDirection);

  @media (max-width: 768px) {
    flex-direction: column;
  }

  &:hover {
    box-shadow: 0 0 15px rgba(0, 0, 0, 0.6);
  }

  .card-img {
    width: 50%;
    overflow: hidden;
    display: flex;
    align-items: center;

    @media (max-width: 768px) {
      width: 100%;
      height: 55%;
    }

    img {
      width: 100%;
      height: 100%;
      object-fit: cover;
      transition: all 0.8s ease;
      border-radius: 10px 10px 0 0;

      &:hover {
        transform: scale(1.3);
      }
    }
  }

  .content {
    width: 50%;
    height: 100%;
    padding: 5px 10px 10px 10px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;

    @media (max-width: 768px) {
      width: 100%;
      height: 45%;
    }

    .card-time {
      font-size: 12px;
      color: var(--text-color3);
    }

    .card-title {
      font-size: 20px;
      font-weight: bold;
      margin: 12px 0;
    }

    .card-interact {
      font-size: 12px;
      color: var(--text-color3);
      margin-bottom: 15px;
      display: flex;

      span:first-child,
      span:last-child {
        display: flex;
        align-items: center;
      }
    }

    .card-tag {
      display: flex;
      justify-content: left;
      align-items: center;

      .tag-item {
        font-size: 14px;
        border-radius: 5px;
        padding: 3px 5px;
        background-color: #eee;
        color: #9d9d9d;
        display: flex;
        align-items: center;
        transition: all 0.3s linear;

        &:hover {
          background-color: #ffa500;
          color: #fff;
        }
      }

      .tag-item {
        margin-right: 10px;
      }

      .tag-item:last-child {
        margin-right: 0;
      }
    }
  }
}
</style>